package com.ruoyi.web.controller.system;

import java.util.Map;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IStatisticsService;

/**
 * 数据统计分析Controller
 *
 * @author ltr
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/system/statistics")
public class StatisticsController extends BaseController
{
    @Autowired
    private IStatisticsService statisticsService;

    /**
     * 获取系统总体概览统计
     * 包括：学生总数、教师总数、题目总数、申请总数等
     */
    @PreAuthorize("@ss.hasRole('admin') or @ss.hasRole('administrator')")
    @GetMapping("/overview")
    public AjaxResult getOverviewStatistics()
    {
        Map<String, Object> data = statisticsService.getOverviewStatistics();
        return success(data);
    }

    /**
     * 获取题目相关统计
     * 包括：难度分布、标签分布、热度排行、录取率等
     */
    @PreAuthorize("@ss.hasRole('admin') or @ss.hasRole('administrator')")
    @GetMapping("/topic")
    public AjaxResult getTopicStatistics()
    {
        Map<String, Object> data = statisticsService.getTopicStatistics();
        return success(data);
    }

    /**
     * 获取教师相关统计
     * 包括：指导学生数排行、题目发布数、录取率、职称分布等
     */
    @PreAuthorize("@ss.hasRole('admin') or @ss.hasRole('administrator')")
    @GetMapping("/teacher")
    public AjaxResult getTeacherStatistics()
    {
        Map<String, Object> data = statisticsService.getTeacherStatistics();
        return success(data);
    }

    /**
     * 获取学生相关统计
     * 包括：年级分布、专业分布、录取状态、GPA分布等
     */
    @PreAuthorize("@ss.hasRole('admin') or @ss.hasRole('administrator')")
    @GetMapping("/student")
    public AjaxResult getStudentStatistics()
    {
        Map<String, Object> data = statisticsService.getStudentStatistics();
        return success(data);
    }

    /**
     * 获取申请相关统计
     * 包括：志愿录取率对比、状态分布、时间趋势等
     */
    @PreAuthorize("@ss.hasRole('admin') or @ss.hasRole('administrator')")
    @GetMapping("/application")
    public AjaxResult getApplicationStatistics()
    {
        Map<String, Object> data = statisticsService.getApplicationStatistics();
        return success(data);
    }

    /**
     * 获取变更申请统计
     * 包括：通过率、趋势、原因分析等
     */
    @PreAuthorize("@ss.hasRole('admin') or @ss.hasRole('administrator')")
    @GetMapping("/changeRequest")
    public AjaxResult getChangeRequestStatistics()
    {
        Map<String, Object> data = statisticsService.getChangeRequestStatistics();
        return success(data);
    }

    /**
     * 获取时间趋势分析
     * 包括：近30天申请趋势、录取趋势、题目发布趋势
     */
    @PreAuthorize("@ss.hasRole('admin') or @ss.hasRole('administrator')")
    @GetMapping("/timeTrend")
    public AjaxResult getTimeTrendStatistics()
    {
        Map<String, Object> data = statisticsService.getTimeTrendStatistics();
        return success(data);
    }

    /**
     * 获取完整的仪表板数据（包含所有统计）
     * 一次性获取所有统计数据，适用于仪表板首页
     */
    @PreAuthorize("@ss.hasRole('admin') or @ss.hasRole('administrator')")
    @Log(title = "数据统计", businessType = BusinessType.OTHER)
    @GetMapping("/dashboard")
    public AjaxResult getDashboardData()
    {
        Map<String, Object> data = statisticsService.getDashboardData();
        return success(data);
    }
}